cap log close

global path = "****"

local name= "cov_het_gen"
local date = "061820"
global logname = "$path/`name'_`date'.log"

clear
set more off
set matsize 11000
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample_prepcode.dta", clear

replace age_2017=0 if age_2017<0
replace age_2017=0 if age_2017<0
rename fpl_frac magi_fpl2015


gen cov2016_11 = (covered2016 - any_dec == 11)
gen age_45_64 = age_2017 < 65 & age_2017 >= 45
gen self_prepared = (prep_tin_flag == "")
gen no_botched_rollout = inlist(state,"CA","CO","CT","DC","KY","MN","NY","RI","WA")
gen income = (magi_fpl2015<=1.38)
gen age_45 = (age_2017 >= 45)

foreach var in exchange medicaid esi off_exchange va medicare{
gen `var'1718 = `var'2017 + `var'2018
}

*Table: Coverage Heterogeneity (interacted and main effects) 

local het_var male married income expansion no_botched_rollout self_prepared age_45

foreach var in `het_var'{
gen `var'_t = `var'*treatment
}				

*Column 1: all ages (intensive margin)
reg covered1718 treatment male married income expansion no_botched_rollout self_prepared age_45 ///
						  male_t married_t income_t expansion_t no_botched_rollout_t self_prepared_t age_45_t if notall16 == 1 , cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_hetgen_2_`date'.ster", replace			
		
*Column 2: 45-64 (intensive margin)		
reg covered1718 treatment male married income expansion no_botched_rollout self_prepared ///
						  male_t married_t income_t expansion_t no_botched_rollout_t self_prepared_t if notall16 == 1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_hetgen_2_`date'.ster", append

*Column 3: all ages (extensive margin)
reg any_covered1718 treatment male married income expansion no_botched_rollout self_prepared age_45 ///
						  male_t married_t income_t expansion_t no_botched_rollout_t self_prepared_t age_45_t if notall16 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_hetgen_2_`date'.ster", append
		
*Column 4: 45-64	(extensive margin)	
reg any_covered1718 treatment male married income expansion no_botched_rollout self_prepared ///
						  male_t married_t income_t expansion_t no_botched_rollout_t self_prepared_t if notall16 == 1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_hetgen_2_`date'.ster", append
			

log close

